package com.jacky.iot.config;

import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.InfluxDBClientFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class InfluxDbConfig {

    @Value("${influxdb.url}")
    private String influxDbUrl;

    @Value("${influxdb.token}")
    private String token;

    @Value("${influxdb.org}")
    private String org;

    @Value("${influxdb.bucket}")
    private String database;

    @Bean
    public InfluxDBClient influxDBClient() {
        return InfluxDBClientFactory.create(influxDbUrl,
                token.toCharArray(),
                org, database);
    }

    public String getInfluxDbUrl() {
        return influxDbUrl;
    }

    public String getToken() {
        return token;
    }

    public String getOrg() {
        return org;
    }

    public String getDatabase() {
        return database;
    }
}
